﻿using System;
using System.Collections.Generic;
using System.Text;

namespace _2023._5._8超市收银系统
{
   
    class SuperMarket
    {
        StoreHouse house = new StoreHouse();
        public SuperMarket()
        {
            house.Instorage("苹果", 1000);
            house.Instorage("华为手机", 1000);
        }
        public void  ShowGoods()
        {
            house.Print();
        }

        public void AskBuying()
        {
            Console.WriteLine("欢迎光临，请问要买点什么,我们有苹果，华为手机");
            Console.WriteLine("物品名称：");
            string name = Console.ReadLine();
            Console.WriteLine("物品数量");
            int count=Convert.ToInt32(Console.ReadLine());
            Goods[] goods = house.OutStorage(name, count);
            double realmoney;
            Console.WriteLine("总共需支付{0}", realmoney=GetMoney(goods));
            Console.WriteLine("请选择折扣方式：1无折扣，2打九折，3打八折，4买500送100,5买2000送500");
            string input = Console.ReadLine();
            DisountFather df;
            switch (input)
            {
                case "1":
                    df = new DiscountNormol();
                    realmoney= df.LastMoney(realmoney);
                    break;
                case "2":
                    df = new DiscountRate(0.9);
                    realmoney = df.LastMoney(realmoney);
                    break;
                case "3":
                    df = new DiscountRate(0.8);
                    realmoney = df.LastMoney(realmoney);
                    break;
                case "4":
                    df = new DiscountMN(500, 100);
                    realmoney = df.LastMoney(realmoney);
                    break;
                case "5":
                    df = new DiscountMN(2000, 500);
                    realmoney = df.LastMoney(realmoney);
                    break;
                default:
                    break;
            }
            Console.WriteLine("打完折后您需付{0}", realmoney);
            Console.WriteLine("以下是你的小票");
            Console.WriteLine("货物名称:{0}\t货物单价{1}\t货物数量:{2}\t应付{3}\t", goods[0].Nmae, goods[0].Price, count, realmoney);
        }


        public double GetMoney(Goods[] goods)
        {
            double money=0;
            for(int i=0;i<goods.Length;i++)
            {
                money += goods[i].Price;
            }
            return money;
        }

    }
}
